home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / ada / adaed-1.11 / adaed-1 / Adaed-1.11.0a / ada.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-07  |  7.0 KB  |  293 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9. #include "config.h"
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <malloc.h>
  13. #include <ctype.h>
  14. #include <string.h>
  15. #include "constant.h"
  16. #include "kinds.h"
  17.  
  18. #define TABFILE "ada.t"
  19. #define CONSTANTFILE "constant.h"
  20.  
  21. #define EOFT "$EOF"
  22. #define ERROR_SYM 0
  23. #define MAXLINE 120
  24. #define MAX_AST 4
  25.  
  26. #define NUM_LINES 20
  27.  
  28.  
  29.  
  30. /* Structure definitions */
  31. struct namelistmap {
  32.     short num;
  33.     char *name;
  34.     struct namelistmap *nextlist;
  35.     struct namelistmap *nextmap;
  36.     };
  37.  
  38. struct tok_loc {
  39.     short line;
  40.     short col;
  41.     };
  42.  
  43. struct token {
  44.     short index;
  45.     struct tok_loc loc;
  46.     };
  47.  
  48. struct prsstack {
  49.     short symbol;
  50.     struct prsstack *prev;
  51.     union {
  52.     struct ast *ast;
  53.     struct token *token;
  54.     } ptr;
  55.     };
  56. struct two_pool {
  57.     struct two_pool *link;
  58.     union {
  59.     int reduction;
  60.     int state;
  61.     struct ast *node;    
  62.     } val;
  63.     };
  64.  
  65. struct ast {
  66.     short kind;
  67.     short count ;
  68.     struct tok_loc span;
  69.     union {
  70.     struct two_pool *list;
  71.     struct ast **subast;
  72.     short val;
  73.     } links;
  74.     };
  75.  
  76. struct tmptok {
  77.     struct token *link;
  78.     };
  79.  
  80. struct tmpnode {
  81.     short kind;        /* set to AS_FREE when first placed on stack */
  82.     short count;
  83.     struct tok_loc span;
  84.     struct ast *link;
  85.     };
  86.  
  87. struct tmpast {
  88.     struct ast **link;
  89.     };
  90.  
  91.  
  92.  
  93.  
  94.  
  95. /* Declarations of functions needed */
  96. extern struct prsstack *(*prsalloc)(unsigned),*copytoken();
  97. extern char *find_name();
  98. extern void (*prsfree)(struct prsstack *, struct prsstack *);
  99. extern struct two_pool *(*talloc)(unsigned);
  100. extern void (*tfree)(struct two_pool *, struct two_pool *);
  101. extern struct token *(*tokalloc)(unsigned);
  102. extern void (*tokfree)(struct token *);
  103. extern struct ast **new_ast(), **astalloc();
  104. extern struct prsstack *gettok();
  105. extern struct two_pool *makenodelist();
  106.  
  107.  
  108. /* Declarations of external variables to be visible */
  109. extern struct tok_loc *lspan, *rspan;
  110. extern struct prsstack *prs_stack, *curtok, *rh[], **tokens;
  111. extern struct two_pool *sta_stack;
  112. extern int tokind, toksiz, tokbottom;
  113. extern FILE  *adafile, *msgfile;
  114. extern struct ast *opt_node, *any_node, *id_node;
  115. extern int lineno, colno, src_index;
  116. extern char *data, *line, source_buf[NUM_LINES][MAXLINE + 1];
  117. extern short lhs[], rhslen[], def_action[]; 
  118. extern short act_tab1[];
  119. extern long act_tab2[];
  120. extern int symcount;
  121. extern struct namelistmap *numtostrtable[], *strtonumtable[], gramsyms[];
  122. extern char islist_node[], islater_declarative_node[], isbody_node[],
  123.     isval_node[], isast_node[],ispredef_pragma[],isimpldef_pragma[],
  124.     isimmediate_decl_pragma[],iscontext_pragma[],iscompilation_pragma[],
  125.     isafter_libunit_pragma[],istask_pragma[],isrepr_pragma[],
  126.     *overloadable_operators[];
  127. extern int redopt, astopt, erropt, termopt, debugopt, trcopt;
  128. extern int err_ct;
  129.  
  130.  
  131. /* Macros */
  132. #define MIN(a,b) (((a) < (b)) ? (a) : (b))
  133. #define MAX(a,b) (((a) > (b)) ? (a) : (b))
  134.  
  135. #define ISTOKEN(node)      ((node)->symbol <= EOFT_SYM)
  136.  
  137.  
  138.  
  139. /* Macros for storage allocation */
  140. #define PRSALLOC() (*prsalloc)(sizeof(struct prsstack))
  141. #define PRSFREE (*prsfree)
  142. #define TALLOC() (*talloc)(sizeof(struct two_pool))
  143. #define TFREE (*tfree)
  144. #define TOKALLOC() (*tokalloc)(sizeof(struct token))
  145. #define TOKFREE (*tokfree)
  146.  
  147.  
  148. /* Error recovery: */
  149.  
  150. /* ALWAYS_PREFERRED_SYMS */
  151. #define in_ALWAYS_PREFERRED_SYMS(t) ((t==65) || (t==75) || (t==80) )
  152.  
  153.  
  154. /* Constants*/
  155. #define MAX_LOOK_AHEAD    25
  156. #define MIN_LEN 1
  157. #define RESERVED_SYMS 64
  158.  
  159. /*  
  160.            DEFINE CANDIDATE TYPES
  161.                   
  162. The map CANDIDATES is a multivalued map from the set
  163.     {'delete','subst','merge','spell-subst','insert'} 
  164. to sets of potential candidates for substitution. Each of these is
  165. represented as a structure containing 
  166.             the token symbol, the number of backup tokens and
  167.             a third value.
  168.                                                     */
  169. #define DELETE 1
  170. #define MERGE  2
  171. #define SUBST  3
  172. #define INSERT 4 
  173. #define SPELL_SUBST 5 
  174. #define C_BOUND 6
  175.  
  176.  
  177. /* Structure definitions */
  178.  
  179. typedef struct cand {
  180.     short token_sym,backup_toks,t3 ;
  181.     struct cand *next ;
  182.     } CAND, *PCAND;
  183.  
  184. /*  
  185.            DEFINE STRING TYPES
  186.                                     */
  187. typedef char * STRING ;
  188. typedef struct stringlist {        /* A list of strings        */
  189.     STRING message ;        /* Points to the text        */
  190.     struct stringlist *next ;   /* Points to the next message   */
  191. }   STRINGLIST ;
  192.  
  193.  
  194.  
  195. /* External variables */
  196. extern FILE *errfile;
  197. extern    int TOKSYMS[] ;
  198. extern    int n_TOKSYMS ;
  199. extern    PCAND CANDIDATES[] ;
  200. extern    int n_CANDIDATES[] ;
  201. extern    int MAX_CHECK ;
  202. extern    int BACKUPTOKS ;
  203. extern struct prsstack *PREVTOK;
  204. extern int n_prs, n_prs_stack, n_sta_stack;
  205. #ifndef IBM_PC
  206. extern    int    ACTION_TOKENS[] ;
  207. #endif
  208. #ifdef IBM_PC
  209. extern    char    ACTION_TOKENS[] ;
  210. #endif
  211. extern    int    ACTION_TOKENS_INDEX[] ;
  212. extern    struct two_pool *POSS_TOK ;
  213. extern int  SHIFT_STATE[];
  214. extern int  SHIFT_STATE_INDEX[];
  215. extern int    primopt,scopeopt,secopt ;
  216.  
  217.  
  218.  
  219. /* External function definitions */
  220.  
  221. extern    struct cand *(*candalloc)(unsigned);
  222. extern struct prsstack *tokfromlist();
  223. extern struct tok_loc *token_location ();
  224.  
  225.  
  226.  
  227.  
  228. /* Macros */
  229.  
  230.  
  231. #define NEXTTOK (((tokind - tokbottom + 1) % toksiz == 0) ? gettok() : \
  232.     tokfromlist())
  233.  
  234. #define nexttok tokens[(tokind - 1 + toksiz) % toksiz]
  235.  
  236. #define ADDTOTOP(tok) tokens[tokind = (tokind + 1) % toksiz] = (tok)
  237.  
  238. #define TOKMINUS (tokind = (tokind - 1 + toksiz) % toksiz)
  239.  
  240. #define CANDALLOC() (*candalloc)(sizeof(struct cand))
  241.  
  242. /* #define QUOTE(t) (token_value_des(t) ? "" : "\"") */
  243.  
  244. #define SEMI_SYM 80
  245.  
  246. #define l_span(x) (ISTOKEN(x)    \
  247.         ? (x->ptr.token->loc)    \
  248.         : (*(get_left_span(x->ptr.ast))))
  249. #define r_span(x) (ISTOKEN(x)    \
  250.         ? (*(make_span(x->ptr.token->loc.line,x->ptr.token->loc.col + \
  251.                    strlen(namelist(x->ptr.token->index)) -1))) \
  252.         : (*(get_right_span(x->ptr.ast))))
  253. #define LLOC(x) (ISTOKEN(x)    \
  254.         ? &(x->ptr.token->loc)    \
  255.         : (get_left_span(x->ptr.ast)))
  256. #define RLOC(x) (ISTOKEN(x)    \
  257.         ? (make_span(x->ptr.token->loc.line,x->ptr.token->loc.col + \
  258.                    strlen(namelist(x->ptr.token->index)) -1)) \
  259.         : (get_right_span(x->ptr.ast)))
  260.  
  261. #define        NOOP ;
  262.  
  263. #define     is_operator(t)     (( t > CHAR_SYM ) && (t < EOFT_SYM)) 
  264. #define     is_terminal(t)     (t <= EOFT_SYM)
  265. #define     is_reserved(t)     (( t > 0 ) && ( t <= RESERVED_SYMS ) )
  266. /* is_opener is now procedure in prserr.c */
  267.  
  268. #define S_TOKSYMS    (MAX_LOOK_AHEAD * 2)
  269.  
  270. #define TOKSTR(symb)  ((symb != ERROR_SYM) ? namelist(symb) : "ERROR_SYMBOL")
  271.  
  272. /* added for change is spans format (store only for terminal nodes */
  273.  
  274. #define N_D_AST1 1
  275. #define N_D_AST2 2
  276. #define N_D_AST3 4
  277. #define N_D_AST4 8
  278. #define N_D_LIST 16
  279. #define N_D_VAL 32
  280. #define N_D_UNQ 64
  281. #define N_D_TYPE 256
  282.  
  283. #define N_AST1_DEFINED(p) TRUE
  284. #define N_AST2_DEFINED(p) (N_DEFINED[p]&N_D_AST2)
  285. #define N_AST3_DEFINED(p) (N_DEFINED[p]&N_D_AST3)
  286. #define N_AST4_DEFINED(p) (N_DEFINED[p]&N_D_AST4)
  287. #define N_VAL_DEFINED(p) (N_DEFINED[p]&N_D_VAL)
  288. #define N_UNQ_DEFINED(p) (N_DEFINED[p]&N_D_UNQ)
  289. #define N_TYPE_DEFINED(p) (N_DEFINED[p]&N_D_TYPE)
  290. #define N_LIST_DEFINED(p) (N_DEFINED[p]&N_D_LIST)
  291.  
  292. extern int N_DEFINED[] ;
  293.